**Opening First Dataset 
use "/Users/lewiskrashnsky/Documents/Princeton/Chris Referendum Project/Data/BC Merged Data/Third Period/2017 General Election.dta"

**Merging. Results of Merge: All 87 Observations Matched (at the electoral district level)
merge m:m ED_NAME ED_ABBREVIATION using "/Users/lewiskrashnsky/Documents/Princeton/Chris Referendum Project/Data/BC Merged Data/Third Period/2020 General Election.dta" 

rename _merge _merge1

merge m:m ED_NAME ED_ABBREVIATION using "/Users/lewiskrashnsky/Documents/Princeton/Chris Referendum Project/Data/BC Merged Data/Third Period/2018 Referendum.dta" 

rename _merge _merge2 


**Cleaning Unnecessary: Total Variables were created in Stata so no need to check for errors. Elections and Referendum were held in different years so voting totals will be different (no need to check for weird totals in concurrent events). 


***Analysis***
*Scatter plots: Liberal Voting 
graph twoway (lfit Percent_FPTP_Vote_2018 Percent_Liberal_Vote_2017) (scatter Percent_FPTP_Vote_2018 Percent_Liberal_Vote_2017)

graph twoway (lfit Percent_FPTP_Vote_2018 Percent_Liberal_Vote_2020) (scatter Percent_FPTP_Vote_2018 Percent_Liberal_Vote_2020)


*Scatter plots: NDP Voting 
graph twoway (lfit Percent_FPTP_Vote_2018 Percent_NDP_Vote_2017) (scatter Percent_FPTP_Vote_2018 Percent_NDP_Vote_2017)

graph twoway (lfit Percent_FPTP_Vote_2018 Percent_NDP_Vote_2020) (scatter Percent_FPTP_Vote_2018 Percent_NDP_Vote_2020)


**New plots with alternate DV 
graph twoway (lfit Percent_PR_Vote_2018 Percent_Liberal_Vote_2017) (scatter Percent_PR_Vote_2018 Percent_Liberal_Vote_2017)

graph twoway (lfit Percent_PR_Vote_2018 Percent_Liberal_Vote_2020) (scatter Percent_PR_Vote_2018 Percent_Liberal_Vote_2020)

graph twoway (lfit Percent_PR_Vote_2018 Percent_NDP_Vote_2017) (scatter Percent_PR_Vote_2018 Percent_NDP_Vote_2017)

graph twoway (lfit Percent_PR_Vote_2018 Percent_NDP_Vote_2020) (scatter Percent_PR_Vote_2018 Percent_NDP_Vote_2020)


*Regression analysis 
regress Percent_PR_Vote_2018 Percent_Liberal_Vote_2017, robust

regress Percent_PR_Vote_2018 Percent_NDP_Vote_2017, robust


**Trying normal transformation of data** 
gen normal_PR_percent_vote = invnormal(Percent_PR_Vote_2018)

gen normal_Liberal_2017_percent_vote = invnormal(Percent_Liberal_Vote_2017)

gen normal_NDP_2017_vote = invnormal(Percent_NDP_Vote_2017)

*Figures of normal transformations of data 
lowess normal_PR_percent_vote normal_Liberal_2017_percent_vote

lowess normal_PR_percent_vote normal_NDP_2017_vote

*Install Outreg
ssc install outreg2

***Multivariate Regression models
regress Percent_PR_Vote_2018 Percent_Liberal_Vote_2017 Percent_NDP_Vote_2017 Percent_Green_Vote_2017, robust 
outreg2 using Multivariate_2018_Models.doc, replace ctitle (Percentage Support for Electoral Reform, 2018 Referendum (OLS))


regress Percent_PR_Vote_2018 Percent_Liberal_Vote_2017 Percent_Green_Vote_2017, robust 
outreg2 using Multivariate_2018_Models_2.doc, replace ctitle (Percentage Support for Electoral Reform, 2018 Referendum (OLS))


regress Percent_PR_Vote_2018 Percent_NDP_Vote_2017 Percent_Green_Vote_2017, robust 
outreg2 using Multivariate_2018_Models_3.doc, replace ctitle (Percentage Support for Electoral Reform, 2018 Referendum (OLS))


**Final models (Weighted and Unweighted)
regress Percent_PR_Vote_2018 Percent_Liberal_Vote_2017, robust 
outreg2 using Supplementary_Model_Unweighted_2018.doc, replace ctitle (Percentage Support for Electoral Reform, 2018 Referendum (OLS))


regress Percent_PR_Vote_2018 Percent_Liberal_Vote_2017 [pweight= Total_Vote_2017], robust 
outreg2 using Supplementary_Model_Weighted_2018.doc, replace ctitle (Percentage Support for Electoral Reform, 2018 Referendum (OLS))
